home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / c / pcw.zip / DEMO_A.C < prev    next >
C/C++ Source or Header  |  1991-12-28  |  9KB  |  229 lines

  1. /**********************************************************/
  2. /* Program-Id.               MousDemo.C                   */
  3. /* Date Written.             07/03/89.                    */
  4. /* Author.                   Stan Milam.                  */
  5. /*                                                        */
  6. /* Comments:  Originally this was test code for the mouse */
  7. /* routines.  Have taken it and cleaned it up and added   */
  8. /* some new function calls.  Over all this program demon- */
  9. /* strates many of the most useful mouse routines as well */
  10. /* as some of the more useful video and window routines.  */
  11. /**********************************************************/
  12.  
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include "pcwproto.h"
  16. #include "keys.h"
  17.  
  18. /**********************************************************/
  19. /*                          Demo1                         */
  20. /*                                                        */
  21. /* Sets up a box which the mouse can not move out of and  */
  22. /* continually updates the position of the mouse.  When   */
  23. /* the left Mouse button pressed move the cursor to Mouse */
  24. /* position and update cursor position line.              */
  25. /**********************************************************/
  26.  
  27. void demo1(void) {
  28.  
  29.   static char *msg[] = {                           /* User messages */
  30.      "Move the Mouse cursor  around and click",
  31.      "the LEFT button. To end this demo click",
  32.      "the RIGHT button",
  33.      NULL
  34.   };
  35.  
  36.   static char *mousepos[] = {
  37.      "Mouse  Position: Row = %2d Col = %2d",       /* Some format strings */
  38.      "Cursor Position: Row = %2d Col = %2d"
  39.   };
  40.  
  41.    int mx_rows, mx_cols;                           /* Max rows & Cols */
  42.    int row = 12, col = 40, bstatus;                /* Mouse Position */
  43.    int urow =  6, ucol = 10;                       /* Box upper corner */
  44.    int lrow = 18, lcol = 70;                       /* Box lower corner */
  45.    WNDPTR *wnd;                                    /* A window handle */
  46.  
  47.    chk_video_state(&mx_rows, &mx_cols);            /* Get max rows & cols */
  48.    set_cursor_size(6,7);
  49.    set_mpos(row, col);                             /* Set mouse position */
  50.    set_cursor_pos(row, col);                       /* Set cursor position */
  51.    bordercolor(LIGHTBLUE, BLACK);                  /* Set border color */
  52.    titlecolor(LIGHTGRAY, BLACK);
  53.    setborder(SINGLESIDES);                         /* Set border type */
  54.    wnd = wframe(urow,ucol,lrow,lcol,7,BLACK);      /* Make a window */
  55.    wtitle(wnd, TOP, MIDDLE, " A Confined Mouse! ");/* Title the window */
  56.    mframe(urow + 1, ucol + 1, lrow - 1, lcol - 1); /* Box in the Mouse */
  57.    qprintf(urow - 2, CENTER, 15, 0, mousepos[0], row, col); /* Write pos */
  58.    qprintf(urow - 1, CENTER,  4, 0, mousepos[1], row, col);
  59.    q_block_write(19,20,RED,BLACK,msg);             /* Write user messages */
  60.    show_mouse();
  61.    do {
  62.       get_mpos(&row, &col, &bstatus);              /* Get Mouse Position */
  63.       qprintf(urow-2,99,15,0,mousepos[0],row, col);/* Write it out */
  64.       if (get_mpressed(LEFT) > 0) {                /* Left Mouse button */
  65.          set_cursor_pos(row, col);                 /* Move cursor there */
  66.          qprintf(urow-1,99,4,0,mousepos[1],row,col);/* Write Cursor pos */
  67.       }
  68.    } while (get_mpressed(RITE) == 0)   ;       /* Unil Rite Mouse Button */
  69.    hide_mouse();                               /* Hide the Mouse */
  70.    wnd = wpop(wnd);                            /* Remove the Mouse */
  71.    set_cursor_size(0,0);
  72.    mframe(1, 1, mx_rows, mx_cols);             /* Remove Mouse constraint */
  73. }
  74.  
  75. /**********************************************************/
  76. /*                          Demo2                         */
  77. /*                                                        */
  78. /* Tell the user which Mouse Button was pressed.          */
  79. /**********************************************************/
  80.  
  81. void demo2(void) {
  82.  
  83.   static char *msg[] = {
  84.      "Move the Mouse Cursor Around Freely",      /* The user info */
  85.      "and press  either  Mouse  button or",
  86.      "press them together.  To  end  this",
  87.      "demo press any key on the keyboard.",
  88.      NULL
  89.   };
  90.  
  91.   static char  *bstat[] = {
  92.      " This is a dummy message     ",
  93.      " You Pressed the Left Button ",             /* Our messages */
  94.      "You Pressed the Right Button ",
  95.      "  You Pressed Both Buttons   "
  96.   };
  97.  
  98.    WNDPTR *wnd;                                  /* A window handle */
  99.    int    ch;
  100.    int    urow = 10, ucol = 22;                  /* Window upper corner */
  101.    int    lrow = 15, lcol = 58;                  /* Window lower corner */
  102.    int    row, col, bstatus;                     /* Mouse Info */
  103.  
  104.    set_mpos(1,1);                                /* Set Mouse position */
  105.    vcls(); show_mouse();                         /* Cls and show mouse */
  106.    bordercolor(RED, LIGHTGRAY);                  /* Set border color */
  107.    titlecolor(BLUE, LIGHTGRAY);                  /* Set title color */
  108.    wnd = wframe(urow, ucol-1, lrow, lcol+1, 0, 7);/* Frame a window */
  109.    wtitle(wnd, TOP, LEFT, " Which Mouse Button? ");/*Title the window */
  110.    w_block_write(wnd, 1, 2,msg); keybrd_flush();  /* Write msg/flush keboard */
  111.    for (;;) {
  112.        ch = keyin();
  113.        get_mpos( &row, &col, &bstatus );
  114.        switch ( ch ) {
  115.            case LEFT_MOUSE_KEY :
  116.               qputs(lrow+1,99,WHITE,0,bstat[bstatus]);
  117.               continue;
  118.            case RITE_MOUSE_KEY :
  119.               qputs(lrow+1,99,RED,0,bstat[bstatus]);
  120.               continue;
  121.            case BOTH_MOUSE_KEY :
  122.               qputs(lrow+1,99,GREEN,0,bstat[bstatus]);
  123.               continue;
  124.        }
  125.        break;
  126.    }
  127.    keybrd_flush();                                /* Flush out keyboard */
  128.    hide_mouse();                                  /* Rats to their holes! */
  129.    wnd = wpop(wnd);                               /* Remove Window */
  130.    vcls();                                        /* Clear the screen */
  131. }                                                 /* We are done. */
  132.  
  133. /**********************************************************/
  134. /*                           Demo3                        */
  135. /*                                                        */
  136. /* More of a window demo than anything else.  Move the    */
  137. /* window to the mouse position when the left mouse button*/
  138. /* has been pressed.                                      */
  139. /**********************************************************/
  140.  
  141. void demo3(WNDPTR **mwnd) {
  142.  
  143.     WNDPTR *wnd;
  144.     int    ch;
  145.     int    urow = 1, ucol = 19;
  146.     int    lrow = 7, lcol = 61;
  147.     int    i=0, row, col, bstatus;
  148.  
  149.     static char format[] = "Move %d";
  150.     static char   *msg[] = {
  151.         "Move the  Mouse  Cursor  freely.  Press",
  152.         "the LEFT  Mouse  key to move the window",
  153.         "around on the screen. Press  the  RIGHT",
  154.         "Mouse key to end the demo.             ",
  155.         NULL
  156.     };
  157.  
  158.     *mwnd = wpop(*mwnd);                     /* Show original screen */
  159.     set_mpos(1,1); show_mouse(); setborder(2);
  160.     wnd = wframe(urow,ucol,lrow,lcol,YELLOW,LIGHTGRAY);
  161.     wtitle(wnd, BOTTOM, RITE, " Moving Windows ");
  162.     w_block_write(wnd, 1,2,msg);             /* Write the message */
  163.     set_wnd_attr(wnd,RED,LIGHTGRAY);         /* Change window attriutes */
  164.     while ((ch = keyin()) != RITE_MOUSE_KEY) {
  165.        if ( ch == LEFT_MOUSE_KEY ) {
  166.           get_mpos(&row, &col, &bstatus);    /* Get Mouse position */
  167.           hide_mouse();                      /* Rats to your holes! */
  168.           wndmove(wnd, row, col);            /* Move the window */
  169.           wprintf(wnd,5,CENTER,format,++i);  /* Tell how many times */
  170.           show_mouse();                      /* Jerry come out Tom is gone! */
  171.        }
  172.     }
  173.     hide_mouse();                            /* Hide the mouse */
  174.     wnd = wpop(wnd);                         /* Remove the window */
  175. }
  176.  
  177. /* Program Initialization */
  178.  
  179. int init_ms2test(WNDPTR **wnd,int *tline,int *bline) {
  180.  
  181.     int  mxr, mxc;
  182.  
  183.     hide_mouse();
  184.     if (_adaptor > CGA) fload(0,8);
  185.     chk_video_state(&mxr, &mxc);
  186.     *wnd = wpush(1,1,mxr,mxc);
  187.     if (*wnd == NULL) return(0);
  188.     get_cursor_size(tline,bline);
  189.     vcls();
  190.     return(1);
  191. }
  192.  
  193. void end_mouse_demo(int tline, int bline) {
  194.  
  195.    int mxr, mxc;
  196.  
  197.    set_cursor_size(tline,bline);
  198.    if (_adaptor > CGA)
  199.        if (_adaptor == EGA) fload(0,14); else fload(0,16);
  200.    chk_video_state(&mxr, &mxc);
  201.    mframe(1,1,mxr,mxc);
  202. }
  203.  
  204. int demo_a(void) {
  205.  
  206.     WNDPTR *wnd, *errwnd;
  207.     int    tline, bline;
  208.     static char *errmsg[] = {
  209.         "Shame on you!                     ",
  210.         "You have not installed your MOUSE!",
  211.         "Try again when you have a MOUSE.  ",
  212.         NULL
  213.     };
  214.  
  215.     if ( !mpresent ) {
  216.          errwnd = wpush(11,20,13,60);
  217.          q_block_write(11,CENTER,RED,BLACK,errmsg);
  218.          keywait(5); errwnd = wpop(errwnd);
  219.          return 1;
  220.     }
  221.  
  222.     if (init_ms2test(&wnd,&tline,&bline) == 0) return(2);
  223.     demo1();
  224.     demo2();
  225.     demo3(&wnd);
  226.     end_mouse_demo(tline,bline);
  227.     return(0);
  228. }
  229.